package com.ruoyi.project.jiaqin.advertcontract.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.jiaqin.advertcontract.domain.JiaqinAdvertContract;
import com.ruoyi.project.jiaqin.advertcontract.service.IJiaqinAdvertContractService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 广告合同Controller
 * 
 * @author LCL
 * @date 2021-10-28
 */
@Controller
@RequestMapping("/jiaqin/advertcontract")
public class JiaqinAdvertContractController extends BaseController
{
    private String prefix = "jiaqin/advertcontract";

    @Autowired
    private IJiaqinAdvertContractService jiaqinAdvertContractService;

    @RequiresPermissions("jiaqin:advertcontract:view")
    @GetMapping()
    public String advertcontract()
    {
        return prefix + "/advertcontract";
    }

    /**
     * 查询广告合同列表
     */
    @RequiresPermissions("jiaqin:advertcontract:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiaqinAdvertContract jiaqinAdvertContract)
    {
        startPage();
        List<JiaqinAdvertContract> list = jiaqinAdvertContractService.selectJiaqinAdvertContractList(jiaqinAdvertContract);
        return getDataTable(list);
    }

    /**
     * 导出广告合同列表
     */
    @RequiresPermissions("jiaqin:advertcontract:export")
    @Log(title = "广告合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiaqinAdvertContract jiaqinAdvertContract)
    {
        List<JiaqinAdvertContract> list = jiaqinAdvertContractService.selectJiaqinAdvertContractList(jiaqinAdvertContract);
        ExcelUtil<JiaqinAdvertContract> util = new ExcelUtil<JiaqinAdvertContract>(JiaqinAdvertContract.class);
        return util.exportExcel(list, "advertcontract");
    }

    /**
     * 新增广告合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告合同
     */
    @RequiresPermissions("jiaqin:advertcontract:add")
    @Log(title = "广告合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiaqinAdvertContract jiaqinAdvertContract)
    {
        return toAjax(jiaqinAdvertContractService.insertJiaqinAdvertContract(jiaqinAdvertContract));
    }

    /**
     * 修改广告合同
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JiaqinAdvertContract jiaqinAdvertContract = jiaqinAdvertContractService.selectJiaqinAdvertContractById(id);
        mmap.put("jiaqinAdvertContract", jiaqinAdvertContract);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告合同
     */
    @RequiresPermissions("jiaqin:advertcontract:edit")
    @Log(title = "广告合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiaqinAdvertContract jiaqinAdvertContract)
    {
        return toAjax(jiaqinAdvertContractService.updateJiaqinAdvertContract(jiaqinAdvertContract));
    }

    /**
     * 删除广告合同
     */
    @RequiresPermissions("jiaqin:advertcontract:remove")
    @Log(title = "广告合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiaqinAdvertContractService.deleteJiaqinAdvertContractByIds(ids));
    }
}
